package com.sanyou.builders;

public class CacheKeyBuilder {
    private final String DEFAULT_KEY_PREFIX = "SANYOU";
    private StringBuffer buffer = new StringBuffer();

    public CacheKeyBuilder(String firstKey){
        buffer.append(firstKey);
    }

    public CacheKeyBuilder(){
        buffer.append(DEFAULT_KEY_PREFIX);
    }

    /**
     * 添加多级key，在原字符串基础上增加":key"
     * @param key
     */
    public CacheKeyBuilder addSecondaryKey(String key){
        if(buffer.length()!=0){
            buffer.append(":");
        }
        buffer.append(key);
        return this;
    }

    public String build(){
        return buffer.toString();
    }
}
